package cn.lili.modules.payment.serviceimpl;

import cn.lili.modules.payment.service.SupplierAuditService;
import cn.lili.modules.store.entity.enums.SupplierAuditEnum;
import cn.lili.modules.supplier.client.SupplierAuditRecordClient;
import cn.lili.modules.supplier.entity.dos.SupplierAuditRecord;
import cn.lili.modules.system.entity.dto.UrbanSubstationAuditSetting;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
@RequiredArgsConstructor
@Slf4j
public class SupplierAuditServiceImpl implements SupplierAuditService {

    private final SupplierAuditRecordClient supplierAuditRecordClient;

    @Override
    public void auditCallback (String payerId, UrbanSubstationAuditSetting urbanSubstationAuditSetting) {
        log.info("支付人ID,{}", payerId);
        SupplierAuditRecord supplierAuditRecord = supplierAuditRecordClient.getBySupplierId(payerId);
        if (null != supplierAuditRecord) {
            supplierAuditRecord.setPaymentTime(new Date());
            supplierAuditRecord.setPaymentMoney(Double.valueOf(urbanSubstationAuditSetting.getAuditMoney()));
            supplierAuditRecord.setPaymentStatus(SupplierAuditEnum.PAID.name());
            supplierAuditRecordClient.update(supplierAuditRecord);
        }
    }
}
